"use strict";
/* Controllers */
app.controller("openaiListController", ['$scope', '$location', '$rootScope', '$routeParams', 'openaiListService', function ($scope, $location, $rootScope, $routeParams, openaiListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};

    var errorFn = function (result) {
        alert(result);
    };
    
    $scope.questionHandle = function() {
        var vm = $scope.vm;
        vm.result.ms = "...";
        // 去除两端空格
        vm.p.question = vm.p.question.replace(/^\s+|\s+$/g,'');
        if(vm.p.question=='') {
            alert("请输入question");
            return;
        }
        var params = {question: vm.p.question};
        var procFn = function (response) {
            if ("000" !== response.code) {
                alert(response.message);
                return ;
            }
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
        };
        openaiListService.questionHandle(params, procFn, errorFn);
    }

    $scope.initializeController = function () {
        vm.result.ms = '';
    };

    $scope.initializeController();

}]);

/* Services */
app.service('openaiListService', ['ajaxService', function (ajaxService) {

    this.questionHandle = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/openai/questionHandle.do", successFunction, errorFunction);
    };
}]);



